
package ThreeDEntities;

import static org.lwjgl.opengl.GL11.*;

public class RectangularPrism implements ThreeDEntity{
    
    
    protected double x,y,z,width,height,depth;
    protected double dX,dY,dZ;
    protected int renderList;

    
    
    public RectangularPrism(double x,double y,double z, double width, double height, double depth){
        this.x=x;
        this.y=y; 
        this.z=z;
        this.width = width;
        this.height = height;
        this.depth = depth;
        renderList = glGenLists(1);
        
            glNewList(renderList, GL_COMPILE);{
            glBegin(GL_QUADS);{
                glVertex3f((float)-width/2,(float) -height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) -height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) height/2,(float) depth/2);
                glVertex3f((float)-width/2,(float) height/2,(float) depth/2);
                
                glVertex3f((float)-width/2,(float) -height/2,(float) -depth/2);
                glVertex3f((float)width/2,(float) -height/2,(float) -depth/2);
                glVertex3f((float)width/2,(float) height/2,(float) -depth/2);
                glVertex3f((float)-width/2,(float) height/2,(float) -depth/2);
                
                glVertex3f((float)-width/2,(float) -height/2,(float) -depth/2);
                glVertex3f((float)-width/2,(float) -height/2,(float) depth/2);
                glVertex3f((float)-width/2,(float) height/2,(float) depth/2);
                glVertex3f((float)-width/2,(float) height/2,(float) -depth/2);
                
                glVertex3f((float)width/2,(float) -height/2,(float) -depth/2);
                glVertex3f((float)width/2,(float) -height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) height/2,(float) -depth/2);
                
                glVertex3f((float)-width/2,(float) height/2,(float) -depth/2);
                glVertex3f((float)-width/2,(float) height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) height/2,(float) -depth/2);
                
                glVertex3f((float)-width/2,(float) -height/2,(float) -depth/2);
                glVertex3f((float)-width/2,(float)-height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) -height/2,(float) depth/2);
                glVertex3f((float)width/2,(float) -height/2,(float) -depth/2);
            }glEnd();
        }glEndList();
    }
    
    
    @Override
    public void render() {
        
        glTranslated(x, y, z);
        glCallList(renderList);
    }

    
    public void update(double delta) {
        move(delta);
        //System.out.println(dX);
        render();
    }

    @Override
    public void setLocation(double x, double y, double z) {
        this.x=x;
        this.y=y; 
        this.z=z;
        
    }

    @Override
    public void setX(double x) {
        this.x=x;
    }

    @Override
    public void setY(double y) {
        this.y=y;
    }

    @Override
    public void setZ(double z) {
        this.z=z;
    }
    
    @Override
    public void setSize(double width, double height, double depth) {
        this.width = width;
        this.height = height;
        this.depth = depth;
    }
    @Override
    public void setWidth(double width) {
        this.width = width;
    }

    @Override
    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public void setDepth(double depth) {
        this.depth = depth;
    }

    @Override
    public double getX() {
        return x;
    }

    @Override
    public double getY() {
      return y;
    }

    @Override
    public double getZ() {
        return z;
    }
    
    public void setSpeed(double dx, double dy, double dz){
        this.dX = dx;
        this.dY = dy;
        this.dZ = dz;
    }
    public void move(double delta){
        x=(x+dX)*delta;
        y=(x+dX)*delta;
        z=(x+dX)*delta;
    }
    public double getWidth(){
        return width;
    }
    public double getHeight(){
        return height;
    }
    public double getDepth(){
        return depth;
    }

    @Override
    public void update() {
        
    }
    

}
